<template>
	<view class="deviceInfoLayout">
		<view class="item">
			{{$t('deviceUpgrade.brand')}}:{{resdata.brand}}
		</view>
		<view class="item">
			imei:{{resdata.imei}}
		</view>
		<view class="item">
			iccid:{{resdata.iccid}}
		</view>

		<view class="item">
			{{$t('deviceUpgrade.model')}}:{{resdata.model}}
		</view>
		<view class="item">
			{{$t('deviceUpgrade.versionCode')}}:{{resdata.osVer}}
		</view>

		<view class="upgrade" :class="isNeedUpgrade == false ?'active':''" @click="upgradeDevice">
			 {{isNeedUpgrade?$t('deviceUpgrade.upgrade'):$t('deviceUpgrade.alreadyNewVersion')}}
		</view>

	</view>
</template>



<script setup>
	import {
		onLoad,
		onShow
	} from "@dcloudio/uni-app";
	import {
		ref
	} from "vue";
	import {
		apiGetDeviceInfo,
		apiDeviceIfNeedUpgrade,
		apiDeviceUpgrade
	} from "../../api/device_api";
	import {
		i18nTool
	} from '../../utils/i18en';
	import {
		os
	} from "../../uni_modules/wu-ui-tools/libs/function";
	import {
		getImei
	} from "../../utils/user_tools";
	const resdata = ref(null);
	const ovData = ref(null);
	const isNeedUpgrade = ref(false);
	var param = {

	};
	let imei = getImei();

	onLoad(async (e) => {
		let {
			data
		} = e;

		resdata.value = JSON.parse(data);

		param = {
			imei: imei,
			osVer: resdata.value.osVer
		}
		let res = await apiDeviceIfNeedUpgrade(param);
		ovData.value = res.content;
		if (!ovData.value) {
			isNeedUpgrade.value = false
			console.log("ssssss", isNeedUpgrade.value);
		} else {
			isNeedUpgrade.value = true
		}
		uni.setNavigationBarTitle({
			title: i18nTool("deviceUpgrade.navTitle")
		})
	})

	async function upgradeDevice() {

		if (!ovData.value) {
			uni.showToast({
				title: "已是最新版本",
				icon: "none"
			})

		} else {
			if (resdata.value.upgrade == 1) {
				let res = await apiDeviceUpgrade(param);
			}
		}
	}
</script>

<style lang="scss" scoped>
	.deviceInfoLayout {
		margin: 40rpx 40rpx;

		.item {
			color: #333;
			font-size: 30rpx;
			height: 80rpx;
			align-items: center;
			display: flex;

		}

		.upgrade {
			margin: 60rpx;
			background-color: $uni-color-theme;
			border-radius: 40rpx;
			height: 80rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			color: #fff;
			font-size: 28rpx;

			&.active {
				background-color: #dddddd;
			}
		}


	}
</style>